# 使用python访问并操作mysql

from pymysql import *


def main():
    # 创建Connection连接
    conn = connect(host='192.168.124.132', port=3306, database='day24', user='root', password='123', charset='utf8')
    # 获得Cursor对象
    cs1 = conn.cursor()
    # 增加
    # count = cs1.execute('insert into goods_cates(name) values("硬盘")')
    # print(count)
    # 修改
    # count=cs1.execute('update goods_cates set name="机械硬盘" where name ="硬盘"')
    # print(count)
    # 删除
    count=cs1.execute('delete from goods_cates where id>10')
    print(count)

    # 提交之前的操作，如果之前已经之执行过多次的execute，那么就都进行提交，忘记commit数据库没改变
    conn.commit()

    # 关闭Cursor对象
    cs1.close()
    # 关闭Connection对象
    conn.close()


if __name__ == '__main__':
    main()
